CC: Drop special handling in recheckApplication #21659
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on #21445
In recheckApplication we implemented a rule that computed the capture set of an
application
f(a)
by being the "better" of either the capture set off
unioncapture set of
a
or the capture set of the result type off(a)
. This relieson capture monotonicity, which we try to get away from. Also, it's semantically
dubious if the type of the argument
a
is a type variable that can be instantiatedto a capturing type as in the following example:
Here, we account for every capability in
IterableOnce[B]^
already inf
. Butthose capabilities could also come from
A
ifA
is instantiated in theactual function argument to a capturing type.
There was extensive breakage once the special handling was dropped. One example is
the
flatMap
definition above. We leave that as a potential soundness hold for now,but the right way to fix
flatMap
would be by adding a capture set variable:The problem is that this currently cannot be done in a way that allows flatMap to be called
as before, passing a single type argument for
B
. We'd have to change the system to eitherallow curried type parameters or optional type parameters for capture sets.
Another issue is that now more reach capabilities are registered as used by the enclosing method.
An example is lazylist-exceptions.scala, which has been moved to pending. Here, the use is spurious
because it happens inside an anonymous class creation on the right hand side of the method.
With refined use checking, the use would not propagate to the method, so the reach capability should
not be leaking. But to get there we need to implement refined use checking first.